// pages/register/register1.js
var http = require('../common/service/http.js');
var kvutil = require('../common/service/kvutil.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    formData: {
      captha: {
        title: "图形验证码",
        holder: "",
        key: "captha",
        value: "",
        barType: "KeyBoardType:number",
        isEnable: true,
        isRequired: true,
        requiredRule: {
          length: "4"
        }
      },
      phone: {
        title: "中国+86",
        holder: "",
        key: "phone",
        value: "",
        barType: "KeyBoardType:number",
        isEnable: true,
        isRequired: true,
        requiredRule: {
          requeiredTip: "手机号",
          length: "11"
        }
      },
      smscode: {
        title: "短信验证码",
        holder: "",
        key: "smscode",
        value: "",
        barType: "KeyBoardType:number",
        isEnable: true,
        isRequired: true,
        requiredRule: {
          length: "4"
        }
      },
    }
  },

  inputBarValue: function(e) {
    // console.log(e);
    var key = e.detail.key;
    var val = e.detail.val;
    this.data.formData[key].value = val;
  },

  extandEvent: function(e) {
    console.log(e);
    var key = e.detail.key;
    if(key.indexOf("captha") === 0){
      var val = e.detail.val;
      this.data.formData[key].value = val;
    }else if(key.indexOf("phone") === 0){
      var checkRequired = http.check_require({phone: this.data.formData.phone});
      if (checkRequired) {
        var fData = {
          m: this.data.formData.phone.value,
          t: "0"
        };
        http.register_send_sms(fData, function(res) {
          
        });
      }
    }
  },

  user_register1: function(e) {
    var kvstr = kvutil.dic_to_string({phone:this.data.formData.phone.value});
    console.log("user_register1" + kvstr);
    wx.navigateTo({
      url: '../register/register2' + '?' + kvstr,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.setNavigationBarTitle({
      title: '免费注册',
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})